
const shellUtil = require('../../common/utils/shellUtil');
const EnvContext = require('../../common/context/EnvContext');
const { createPackage } = require('../../core/pluginSetupService/createPackage');
const { installPackage } = require('../../core/pluginSetupService/installPackage');

const { runIndependentPlugin } = require('../../core/pluginRunService/runIndependentPlugin');
const { getPluginByName } = require('../../core/pluginSearchService/getPluginByName');


exports.runPlugin = function (event, request) {
    const type = request.type
    if (type == "app") {
        EnvContext.getInstance().mainWin.hide()
        shellUtil.runCmd(request)
    } else if (type == "shellCommand") {
        shellUtil.runCmd(request)
    } else if (type == "function") {
        runPluginByFunction(request, event)
    }
}


exports.runSysPluginByName = function (event, request) {
    EnvContext.getInstance().mainWin.hide()
    const artifactId = request.name
    const groupId = "com.appBridge.core"
    getPluginByName(artifactId, groupId).then((plugin) => { runIndependentPlugin(plugin) })

}






function runPluginByFunction(request, event) {
    const action = request.action
    if (action == "createPackage") {
        createPackage(request, event)
    } else if (action == "setupPackage") {
        installPackage(request, event)
    }

}